<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:fmt="http://java.sun.com/jsp/jstl/fmt" xmlns:c="">
<head>
    <meta charset="UTF-8">
    <title>PetStore Management</title>
<!--    <link rel="Stylesheet" href="../css/jpetstore.css" type="text/css" media="screen"/>-->
    <script type="text/javascript" src="../js/jquery-3.6.0.min.js"></script>
    <!--导入jquery-ui-->
    <script type="text/javascript" src="../js/jquery-ui.min.js"></script>
    <link type="text/css" href="../js/jquery-ui.min.css" rel="stylesheet">
</head>
<style>
    *{
        padding: 0px;
        margin: 0px;
    }
    #Content {
        width: 100%;
        height: auto;
        color: #333;
        background-color: rgba(256,256,256,0.5);
        border-width: 0;
        position: relative;
        overflow: hidden;
    }
    a{
        display: block;
        text-decoration: none;
        color: #eaac00;
        font-weight: bold;
    }
    .Returnto{
        display: inline-block;
        float: left;
        position: absolute;
        top: 1ex;
        left: 2ex;
        height: 5ex;
        width: 50ex;
        background-image: url("../image/ReturntoManagementMainMenu.png");
        background-size: 100%;
        background-repeat: no-repeat;
        border-color: #eaac00;
        border-width: 0.4ex;
        border-style: solid;
    }
    table{
        display: block;
        /*position: absolute;*/
        /*top: 10ex;*/
        /*left: 10ex;*/
        margin-top: 10%;
        margin-left: 32%;
        width: 45ex;
        font-size: 3ex;
        background-color: #ffffff;
        border-color: #56832c;
        border-width: 1ex;
        border-style: solid;
    }
    table tr{
        height: 3ex;
        text-align: left;
    }
    table td{
        width: 10ex;
    }
    #search {
        width: 40%;
        height: 7ex;
        background-color: #ffffff;
        border-color: #56832c;
        border-width: 0.7ex;
        border-style: solid;
        text-align: center;
        color: #eaac00;
        position: absolute;
        display: inline-block;
        top: 1ex;
        left: 57ex;
    }

    input {
        float: left;
        position: absolute;
        border-width: .3ex .3ex .3ex .3ex;
        border-style: solid;
        border-color: #eaac00;
        background-color: #ffffff;
        color: #eaac00;
        height: 3ex;
        font-size: 3ex;
    }
    #search span{
        display: inline-block;
        float: left;
        position: absolute;
        font-size: 3ex;
    }
    h2{

        float: left;
        position: absolute;
        top: 5ex;
        left: 35ex;
        font-size: 5ex;
    }
    .ADDNEWITEM{
        display: inline-block;
        float: left;
        margin-left: 80ex;
        margin-top: 2ex;
        margin-bottom: 3ex;
        height: 5ex;
        width: 40ex;
        background-image: url("../image/ADDNEWITEM.png");
        background-size: 100%;
        background-repeat: no-repeat;
        border-color: #eaac00;
        border-width: 0.4ex;
        border-style: solid;
    }
    .RETURN{
        display: inline-block;
        float: left;
        margin-left: -75ex;
        margin-top: 3ex;
        margin-bottom: 3ex;
        width: 10ex;
        background-image: url("../image/RETURN2.png");
        background-size: 100%;
        background-repeat: no-repeat;
        border-color: #eaac00;
        border-width: 0.4ex;
        border-style: solid;
    }
</style>
<body>
<div th:replace="manageCommon/managetop"></div>
</div>

<div id="Content">
    <a class="Returnto" href="/manage/main"></a>
    <div id="search">
        <div id="searchContent">
            <!--搜索-->
            <form action="" method="post" id="keyForm">
                <!--右侧搜索选择复选框-->
                <span style="left: 1ex;top: 1ex ">category:</span>
                <input style="left: 9.5ex;top: 0.8ex;width: 2ex" type="radio" name="select" id="category"/>
                <span style="left: 13ex;top: 1ex">product:</span>
                <input style="left: 20ex;top: 0.9ex;width: 2.1ex" type="radio" name="select" id="product"/>
                <!--开启自动补全功能autocomplete="on"-->
                <input  style="left: 25ex;top: 0.6ex;width: 18ex"id="searchText" type="text" name="keyword" size="14" />
                <input style="left: 44ex;top: 1ex;width: 7ex" type="button" name="searchProducts" value="Search" id="searchSubmit"/>
            </form>
        </div>
    </div>
    <!--    category选择-->
    <div>
        <h2>Item List</h2>
        <form th:hidden="${session.manageitemList==null}">
            <table>
                <tr>
                    <th>Item id</th>
                    <th>&nbsp;&nbsp;&nbsp;&nbsp;</th>
                    <th>&nbsp;&nbsp;&nbsp;&nbsp;</th>
                </tr>
                <tr th:each="item:${session.manageitemList}">
                    <td th:text="${item.itemId}"></td>
                    <td><a th:onclick="showItemDetails('[[${item.itemId}]]')">进入</a></td>
                    <td><a th:onclick="deleteItem('[[${item.itemId}]]'+'[[${item.getProduct().getProductId()}]]')">删除</a></td>
                </tr>
            </table>
            <a class="ADDNEWITEM" th:href="@{'/manage/newItemForm'}"></a>
            <input class="RETURN"  type="button"  th:onclick="returnProductList('[[${session.beforCategory}]]')"/>
        </form>
    </div>
    <script>
        $(function (){
            //对搜索输入框的键盘按下后的事件进行监听keyup
            $('#searchText').on("keyup",function (){
                let datas={"word":$('#searchText').val()};
                $.post('/catalog/completeSearch',datas,function (data){

                });
                $.ajax({
                    //连接数据库进行查询
                    type:"GET",
                    url:"/catalog/completeSearch",
                    data:{"keyword":$('#searchText').val()},
                    dataType:"json",
                    success:function (data){
                        console.log("888888888888");
                        //创建数组用于存放获取的产品的名字
                        var searchResult=new Array();
                        for(var i=0;i<data.length;i++){
                            searchResult[i]=data[i].name;
                        }
                        //console.log(searchResult);
                        //将产品名显示在UI控件中
                        $('#searchText').autocomplete({
                            source:searchResult
                        });
                    }
                });
            });
            $('#searchSubmit').on('click',function (e) {
                e.preventDefault();
                console.log("点击搜索按钮");
                let datas = $('#keyForm').serialize();
                $.post('/catalog/searchProduct',datas,function (data){
                    if(data.code === 11)
                    {
                        console.log("搜索成功");
                        location.href = data.msg;
                    }

                });
            });
        });
        function showItemDetails(itemid){
            console.log(itemid);
            var str=itemid.split('"');
            location.href = "/manage/showItemDetails?itemId="+str[1];
        }
        function deleteItem(itemid){
            console.log(itemid);
            var str1=itemid.split('"');
            console.log(str1[3]);

             location.href = "/manage/deleteItem?itemId="+str1[1]+"&productId="+str1[3];
        }
        function returnProductList(categoryId){
            var str2=categoryId.split('"');
            location.href = "/manage/intoProductPage?cateid="+str2[1];
        }
    </script>
</div>
<div th:replace="manageCommon/managebottom"></div>
</body>
</html>